package com.sqlcheck.dto.request;

import com.sqlcheck.enums.GitPlatform;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.util.Map;

@Data
@Schema(description = "创建扫描任务请求（支持临时凭据）")
public class CreateScanTaskWithCredentialsRequest {

    @NotBlank(message = "任务名称不能为空")
    @Schema(description = "任务名称", example = "项目A的SQL兼容性扫描", required = true, maxLength = 100)
    private String taskName;

    @NotNull(message = "任务类型不能为空")
    @Schema(description = "任务类型", example = "GIT_SOURCE_SCAN", required = true, allowableValues = { "PROJECT_SCAN",
            "GIT_SOURCE_SCAN",
            "DATABASE_DDL_SCAN", "MANUAL_SQL" })
    private String taskType;

    @Schema(description = "关联的项目ID，用于项目扫描任务", example = "1")
    private Long projectId;

    @Schema(description = "分支名称，用于Git扫描任务", example = "main")
    private String branchName;

    @Schema(description = "任务描述", example = "对项目A进行Oracle到GoldenDB的兼容性扫描分析")
    private String description;

    @Schema(description = "任务配置参数，JSON格式的配置信息", example = """
            {
                "sourceDbType": "ORACLE",
                "targetDbType": "GOLDENDB",
                "taskType": "GIT_SOURCE_SCAN",
                "gitPlatform": "GITLAB",
                "repositoryUrl": "https://gitlab.com/user/repo",
                "branchName": "master",
                "analysisEngine": "RULE_BASED"
            }
            """)
    private Map<String, Object> config;

    @Schema(description = "分析引擎类型", example = "RULE_BASED", allowableValues = { "RULE_BASED", "LLM_BASED" })
    private String analysisEngine = "RULE_BASED";

    @Schema(description = "是否启用AI增强分析", example = "false")
    private Boolean aiEnhancementEnabled = false;

    @Schema(description = "Git平台")
    private GitPlatform gitPlatform;

    @Schema(description = "Git仓库地址", example = "https://gitlab.com/user/repository")
    private String gitRepositoryUrl;

    @Schema(description = "个人访问令牌（当使用PERSONAL_TOKEN模式时）", example = "glpat-xxxxxxxxxxxxxxxxxxxx")
    private String personalAccessToken;

    @Schema(description = "临时凭据过期时间（分钟），默认60分钟", example = "60")
    private Integer credentialExpirationMinutes = 60;

    // 数据库相关的临时凭据
    @Schema(description = "是否启用数据库扫描")
    private Boolean enableDatabaseScan = false;

    @Schema(description = "数据库主机地址", example = "localhost")
    private String databaseHost;

    @Schema(description = "数据库端口", example = "3306")
    private Integer databasePort;

    @Schema(description = "数据库名称", example = "test_db")
    private String databaseName;

    @Schema(description = "数据库用户名", example = "db_user")
    private String databaseUsername;

    @Schema(description = "数据库密码（临时存储，不持久化）", example = "db_password")
    private String databasePassword;

    // 新增字段：数据库版本和DDL提取选项
    @Schema(description = "数据库版本", example = "8.0")
    private String databaseVersion;

    @Schema(description = "数据库Schema名称", example = "public")
    private String databaseSchema;

    @Schema(description = "Oracle连接方式", example = "SERVICE_NAME", allowableValues = { "SERVICE_NAME", "SID" })
    private String oracleConnectionType = "SERVICE_NAME";

    @Schema(description = "DDL提取选项")
    private DDLExtractionOptions ddlExtractionOptions;

    @Data
    @Schema(description = "DDL提取选项")
    public static class DDLExtractionOptions {
        @Schema(description = "是否包含视图")
        private Boolean includeViews = true;

        @Schema(description = "是否包含索引")
        private Boolean includeIndexes = true;

        @Schema(description = "是否包含约束")
        private Boolean includeConstraints = true;

        @Schema(description = "目标表名列表")
        private java.util.List<String> targetTables;
    }
}